<%@page import="实体类.PageInfo"%>
<%@page import="实体类.Student"%>
<%@page import="java.util.ArrayList"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" type="text/css" href="static/bootstrap-3.3.7-dist/css/bootstrap.css"/>
</head>
<body>
	<!-- 在JSP页面中可以嵌套Java代码 -->
 		
 		<a href="${pageContext.request.contextPath}/student?method=selectStudentInsertPage" class="btn btn-success">添加</a>
 		<table class="table table-striped table-bordered table-hover table-condensed">
			<tr>
				<th>ID</th>
				<th>名字</th>
				<th>年龄</th>
				<th>性别</th>
				<th>班级id</th>
				<th>删除</th> 
				<th>修改</th> 
			</tr>
			<c:forEach items="${pageInfo.list}" var="student">
				<tr>
						<td>${student.id}</td>
						<td>${student.name}</td>
						<td>${student.age}</td>
						<td>${student.gender}</td>
						<td>${student.banjiId}</td>
						<td><a href= "javascript:deleteById(${student.id})">删除</a></td>
						<td><a href= "${pageContext.request.contextPath}/student?method=selectById&id=${student.id}">修改</a></td>
					</tr>
			</c:forEach>
			
		</table>
		<nav aria-label="Page navigation">
		  <ul class="pagination">
		  <c:choose>
		  	<c:when test="${pageInfo.pageNo == 1}">
		  		<li>
		      		<a aria-label="Previous">
		        		<span aria-hidden="true">&laquo;</span>
		     		 </a>
		    	</li>
		  	</c:when>
		  	<c:otherwise>
		  		<li>
		      		<a href="${pageContext.request.contextPath}/student?method=selectByPage&pageNo=${pageInfo.pageNo - 1}" aria-label="Previous">
		        		<span aria-hidden="true">&laquo;</span>
		      		</a>
		    	</li>
		  	</c:otherwise>
		  </c:choose>
		    
		    <c:forEach begin="1" end="${pageInfo.totalPage}" var="i">
		    	<c:choose>
		    		<c:when test="${pageInfo.pageNo == i }">
		    			<li><a>${i}</a></li>
		    		</c:when>
		    		<c:otherwise>
		    			<li><a href="${pageContext.request.contextPath}/student?method=selectByPage&pageNo=${i}">${i}</a></li>
		    		</c:otherwise>
		    	</c:choose>
		    </c:forEach>
		    			
		   <c:choose>
		   		<c:when test="${pageInfo.pageNo == pageInfo.totalPage }">
		   			<li>
		      			<a aria-label="Previous">
		        			<span aria-hidden="true">&raquo;</span>
		     		 	</a>
		    		</li>
		   		</c:when>
		   		<c:otherwise>
		   			<li>
		      			<a href="${pageContext.request.contextPath}/student?method=selectByPage&pageNo=${pageInfo.pageNo + 1}" aria-label="Previous">
		        			<span aria-hidden="true">&raquo;</span>
		      			</a>
		    		</li>
		   		</c:otherwise>
		   </c:choose>
		  </ul>
		</nav>
		
		<script type="text/javascript">
			function deleteById(id){
				var isDelete = confirm('您确认要删除么？');
				if(isDelete){
					location.href = '${pageContext.request.contextPath}/student?method=deleteById&id=' + id + '&pageNo=' + ${pageInfo.pageNo};
				}
			}
		</script>
		
</body>
</html>